"""
Case Type   : gs_preupgradechk工具
Case Name   : gs_upgradectl --help工具介绍新增-skip-resource-check
Create At   : 2025/11/17
Owner       : chen
Description :
    1.gs_upgradectl  --help
Expect      :
    1.--skip-resource-check添加此参数项的介绍
History     :
"""

import unittest
import os
import re
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Common import Common
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

LOG = Logger()
primary_sh = CommonSH('PrimaryDbUser')

class Tools_Gs_Preupgradechk_TestCase0019(unittest.TestCase):
    def setUp(self):
        LOG.info(f'----{os.path.basename(__file__)} start----')
        self.pri_node = Node('PrimaryDbUser')
        self.com = Common()
        self.constant = Constant()
        LOG.info("---SetUp：检查数据库状态是否正常---")
        status = primary_sh.get_db_cluster_status()
        LOG.info(status)
        self.assertTrue("Degraded" in status or "Normal" in status)

    def test_gs_preupgradechk_tools(self):
        text = '----step1: gs_upgradectl --help; ' \
            'expect: --skip-resource-check添加此参数项----'
        LOG.info(text)
        LOG.info(text)
        cmd = f"gs_upgradectl --help"
        LOG.info(cmd)
        result = self.pri_node.sh(f"source {macro.DB_ENV_PATH};"
                                    f"{cmd}").result()
        LOG.info(result)
        self.assertIn('--skip-resouce-check            Skip resource check',
                     result)

    def tearDown(self):
        LOG.info('--------清理环境--------')
        status = primary_sh.get_db_cluster_status("detail")
        LOG.info(status)
        self.assertTrue("Degraded" in status or "Normal" in status)
        LOG.info(f"------{os.path.basename(__file__)} end------")
